package com.senseuni.da.ui.views

import android.content.Context
import android.util.AttributeSet
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.senseuni.da.R

class NotificationView @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0,
    defStyleRes: Int = 0
) : FrameLayout(context, attrs, defStyleAttr, defStyleRes) {

    private val closeView: ImageView
    private val titleView: TextView
    private val subTitleView: TextView

    init {
        // 初始化布局
        inflate(context, R.layout.layout_notification_view, this)

        // 获取子视图
        closeView = findViewById(R.id.iv_close)
        titleView = findViewById(R.id.tv_title)
        subTitleView = findViewById(R.id.tv_sub_title)

        closeView.setOnClickListener {
            hide()
        }
    }

    fun setTitle(text: String) {
        titleView.text = text
    }

    fun setSubTitle(text: String) {
        subTitleView.text = text
    }

    fun show() {
        visibility = VISIBLE
    }

    fun hide() {
        visibility = GONE
    }
}
